package com.guit.hrms.listener;

import com.guit.hrms.event.OfferCreatedEvent;
import com.guit.hrms.manager.DynamicTaskManager;
import com.guit.hrms.po.interview.Offer;
import com.guit.hrms.service.IntervieweeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class OfferEventListener {

    @Autowired
    private DynamicTaskManager taskManager;
    
    @Autowired
    private IntervieweeService intervieweeService;

    @EventListener
    public void handleOfferCreatedEvent(OfferCreatedEvent event) {
        Offer offer = event.getOffer();
        taskManager.addTask(
            offer.getId(),
            offer,
            () -> intervieweeService.checkOfferExpiry(offer.getId())
        );
    }
}
